package net.techfuser.channelorderreport.summary;

import com.alibaba.fastjson.JSONObject;
import net.techfuser.channelorderreport.ChannelOrder;


/**
 * @Description:
 * @Author 左龙龙
 * @Date 21-5-27
 * @Version 1.0
 **/
public class CompleteTimeSummary implements Summary{

    ChannelOrder last = null, cur = null;


    @Override
    public void summary(JSONObject order) {
        last = cur;
        String channel_keyword = order.getString("channel_keyword");
        if("JDDJ".equals(channel_keyword)){

            if(order.containsKey("complete_time")){
                cur = new ChannelOrder();
                cur.date = order.getDate("complete_time");
                cur.complate_order_num = 1;

                // 原价金额-单品优惠总额
                cur.channel_gmv_value = order.getDoubleValue("total_item_yj") - order.getDoubleValue("total_dp_disc");
            }
        }
    }

    @Override
    public ChannelOrder getChange() {
        if(null == last && cur == null){
            return null;
        }else if(cur == null){
            ChannelOrder change = new ChannelOrder();
            change.date = last.date;
            change.complate_order_num = 0 - last.complate_order_num;
            change.channel_gmv_value = 0 - last.channel_gmv_value;
            return change;
        }else if(last == null){
            return cur;
        }else{
            ChannelOrder change = new ChannelOrder();
            change.date = cur.date;
            change.complate_order_num = cur.complate_order_num - last.complate_order_num;
            change.channel_gmv_value = cur.channel_gmv_value - last.channel_gmv_value;
            return change;
        }
    }


}

